package org.agony2d.gpu {
	import org.agony2d.core.agony_internal;
	import org.agony2d.gpu.core.ImageAABase;
	
	use namespace agony_internal;
	
	/** [ TintedImageAA ]
	 *  [◆]
	 *  	1.  textureData
	 *  	2.  color
	 */
public class TintedImageAA extends ImageAABase {
  
    public function TintedImageAA() {
		m_color = 0xFFFFFF
		m_tintChanged = true
    }
	
	public function get color() : uint {
		return m_color
	}
	
	public function set color( v:uint ) : void {
		if (m_color != v) {
			m_color = v
			m_tintChanged = true
		}
	}
	
	override public function set alpha( v:Number ) : void {
		if (m_alpha != v) {
			m_alpha = v
			m_tintChanged = true
		}
	}
	
	
	agony_internal var m_color:uint
	agony_internal var m_tintChanged:Boolean
	
	
	override agony_internal function render( vertexChanged:Boolean, tinted:Boolean ) : void {
		if (!m_textureData || m_invisible) {
			return
		}
		// color × alpha...
		if (tinted && (m_tintChanged || (m_cachedAlpha != m_parent.m_cachedAlpha * m_alpha))) {
			m_cachedAlpha = m_parent.m_cachedAlpha * m_alpha
			m_combine.setTint((int(m_cachedAlpha * 255.0) << 24) | m_color)
			m_tintChanged = false
		}
		super.render(vertexChanged, tinted)
	}
}
}